package com.hz.springboot01.exception;

import com.hz.springboot01.util.ResultJSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常统一处理
 */
@ControllerAdvice(basePackages = "com.hz.springboot01") //只要  该包下边有异常 就进行捕获
@Slf4j
public class GlobalException {
    @ExceptionHandler(SmbmsException.class)
    @ResponseBody
    public ResultJSON handleException(SmbmsException e){

        log.error("自定义异常:",e);
        return ResultJSON.error("自定义异常:"+e);
    }
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ResultJSON handleException(RuntimeException e){

        log.error("系统异常:",e);
        return ResultJSON.error("系统异常:"+e);
    }


}
